<html>
<head><meta charset="utf-8"><title>impl const Trait design · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html">impl const Trait design</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="217939416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/217939416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#217939416">(Nov 25 2020 at 21:06)</a>:</h4>
<p>Doesn't the design of <code>impl const Trait</code> mean that you can only either have none of the functions be const or all of them be const? Is that intentional/am I wrong?</p>
<p>(Note: not sure if this should have been posted in <a class="stream" data-stream-id="144729" href="/#narrow/stream/144729-wg-traits">#wg-traits</a> but the RFC was proposed in const-eval, so I posted here.)</p>



<a name="217939943"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/217939943" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#217939943">(Nov 25 2020 at 21:11)</a>:</h4>
<p>yes, that's intentional</p>



<a name="217941893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/217941893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#217941893">(Nov 25 2020 at 21:30)</a>:</h4>
<p>I think it's intentional because the main goal is to allow <code>where T: const Foo</code> (well, I don't remember if that's exposed, but the semantics at least).</p>
<p>Over-constraining individual methods might happen too, <a href="https://github.com/rust-lang/rfcs/pull/2316">https://github.com/rust-lang/rfcs/pull/2316</a> -style, but that's something different.</p>



<a name="217942033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/217942033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#217942033">(Nov 25 2020 at 21:31)</a>:</h4>
<p>Ah, okay; sounds reasonable as long as there is the ability to constrain just specific functions without constraining the whole trait</p>



<a name="217942389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/217942389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#217942389">(Nov 25 2020 at 21:35)</a>:</h4>
<p>I don't think that will happen if we follow the current design</p>



<a name="217942558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/217942558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#217942558">(Nov 25 2020 at 21:37)</a>:</h4>
<p>If you write a trait impl where only a subset of methods is <code>const</code> you couldn't abstract over it and use it to fulfill <code>where</code>-clauses</p>



<a name="217942641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/217942641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#217942641">(Nov 25 2020 at 21:38)</a>:</h4>
<p>And I don't really see the use cases in having eg. <code>const fn</code> in the <em>trait definition</em> and <em>requiring</em> all impls to make some method <code>const</code></p>



<a name="217951139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/217951139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#217951139">(Nov 25 2020 at 23:31)</a>:</h4>
<p>I belive the use case is to then have a provided const fn that uses this required const fn</p>



<a name="218036359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218036359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218036359">(Nov 26 2020 at 20:32)</a>:</h4>
<p>What I'm talking about is (e.g.) this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="w"> </span><span class="nb">PartialEq</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="c1">//  vvvvv</span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="k">fn</span> <span class="nf">eq</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">other</span>: <span class="kp">&amp;</span><span class="nc">Self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">bool</span> <span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="c1">// ...</span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>So that <code>eq()</code> is <code>const</code> <strong>only for this type</strong>. That way, specific functions in the impl of that trait can be used in more contexts than the definition of the trait itself. I'm not sure if this would somehow break Rust's semver guarantees, but I don't <em>think</em> it would since we're making the implementation more general, <em>not</em> more specific.</p>



<a name="218036392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218036392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218036392">(Nov 26 2020 at 20:33)</a>:</h4>
<p>(This particular case could be handled by <code>impl const PartialEq</code>, but there are likely cases of other traits that have multiple functions, some of should be const and some which should not.)</p>



<a name="218036611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218036611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218036611">(Nov 26 2020 at 20:37)</a>:</h4>
<p><span class="user-mention" data-user-id="249222">@Elichai Turkel</span> good point, this is currently erroneously accepted</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Tr</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">req</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">);</span><span class="w"></span>

<span class="w">    </span><span class="k">fn</span> <span class="nf">prov</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">"lul"</span><span class="p">);</span><span class="w"></span>
<span class="w">        </span><span class="bp">self</span><span class="p">.</span><span class="n">req</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">S</span><span class="p">;</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">Tr</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">req</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="218036698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218036698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218036698">(Nov 26 2020 at 20:38)</a>:</h4>
<p><span class="user-mention" data-user-id="307537">@Camelid</span> the problem with that is that the impl cannot be used to fulfill a <code>const</code> trait bound, despite containing <code>const fn</code>s, which is pretty confusing</p>



<a name="218036832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218036832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218036832">(Nov 26 2020 at 20:40)</a>:</h4>
<p>filed <a href="https://github.com/rust-lang/rust/issues/79450">https://github.com/rust-lang/rust/issues/79450</a> for the snippet above</p>



<a name="218036925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218036925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218036925">(Nov 26 2020 at 20:42)</a>:</h4>
<p>(the primary motivation for this feature is to allow generic bounds in <code>const</code> contexts, and for that, whole <em>impls</em> need to be const, not just a subset of their methods)</p>



<a name="218036952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218036952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218036952">(Nov 26 2020 at 20:42)</a>:</h4>
<p>if you just need specific methods for specific types, just put them in an inherent <code>impl</code></p>



<a name="218036962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218036962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218036962">(Nov 26 2020 at 20:42)</a>:</h4>
<p>or split the trait so that one of them is const-implementable</p>



<a name="218037067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218037067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218037067">(Nov 26 2020 at 20:44)</a>:</h4>
<p>What I was talking about is the ability to assign the result to a <code>const</code>:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">const</span><span class="w"> </span><span class="n">FOO</span>: <span class="cm">/* some type */</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="cm">/* calling a trait method */</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="218037097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218037097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218037097">(Nov 26 2020 at 20:45)</a>:</h4>
<p>Where you want to implement a trait so that the struct satisfies trait bounds, but in a couple places you want to use the trait method on the type concretely in a const context</p>



<a name="218038263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218038263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218038263">(Nov 26 2020 at 21:04)</a>:</h4>
<p>yes, that already works with inherent impl methods</p>



<a name="218038401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218038401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218038401">(Nov 26 2020 at 21:06)</a>:</h4>
<p>Yeah, but there's no way to do it for <em>trait</em> impl methods</p>



<a name="218038413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218038413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218038413">(Nov 26 2020 at 21:06)</a>:</h4>
<p>Unless we're talking past each other :)</p>



<a name="218038558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218038558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218038558">(Nov 26 2020 at 21:08)</a>:</h4>
<p>no, I'm saying that you don't really <em>need</em> this feature to call such methods, there is a trivial workaround</p>



<a name="218039024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218039024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218039024">(Nov 26 2020 at 21:16)</a>:</h4>
<p>Hmm, I'm not sure what you mean</p>



<a name="218039059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218039059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218039059">(Nov 26 2020 at 21:17)</a>:</h4>
<p>Are you saying that the workaround is you define an inherent const fn and then have the trait impl call that?</p>



<a name="218040264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218040264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218040264">(Nov 26 2020 at 21:40)</a>:</h4>
<p>yeah</p>



<a name="218156793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218156793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218156793">(Nov 28 2020 at 09:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/impl.20const.20Trait.20design/near/217942558">said</a>:</p>
<blockquote>
<p>If you write a trait impl where only a subset of methods is <code>const</code> you couldn't abstract over it and use it to fulfill <code>where</code>-clauses</p>
</blockquote>
<p>well, you could imagine dividing the set of <code>fn</code> in a <code>trait</code> in two sets: those that have to be <code>const</code> for a <code>const impl</code>, and those that do not. a <code>const Trait</code> bound would then only allow you to use the const-fns of the trait to be called in const context.</p>



<a name="218157343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218157343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218157343">(Nov 28 2020 at 10:02)</a>:</h4>
<p>in the beginning you'll need to split your trait into two in order to support this. One trait for the ones you definitely need as <code>const fn</code> and one trait for those where you want to do non-const things</p>



<a name="218157347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218157347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218157347">(Nov 28 2020 at 10:03)</a>:</h4>
<p>we may then figure out some syntax sugar for this pattern</p>



<a name="218157512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218157512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218157512">(Nov 28 2020 at 10:07)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/impl.20const.20Trait.20design/near/218157343">said</a>:</p>
<blockquote>
<p>in the beginning you'll need to split your trait into two in order to support this. One trait for the ones you definitely need as <code>const fn</code> and one trait for those where you want to do non-const things</p>
</blockquote>
<p>that won't always be possible if there are interactions through associated types.<br>
(it's okay not to support eveything, just saying I think that work-around is not universal)</p>



<a name="218616783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/impl%20const%20Trait%20design/near/218616783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/impl.20const.20Trait.20design.html#218616783">(Dec 02 2020 at 20:43)</a>:</h4>
<p>I would love to get some additional language features to help with splitting traits, or with subtraits, or similar.  Like if you could offer default implementations for supertrait methods that'd help for splitting, but could also be a not-exactly-specialization way for <code>Copy</code> to provide an implementation for <code>Clone::clone</code>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>